#!/bin/bash

# create a temp dir
echo "--- Make patch dir"
rm -rf patch
mkdir patch

# get the v8 source
echo "--- Get the V8 source"
cd patch
svn checkout http://v8.googlecode.com/svn/trunk/ v8 1>/dev/null

# copy v8 to dir which will be updated by ecmascript-ast build script
echo "--- Copy v8 dir to v8ast dir"
cp -r v8 v8ast

# do the build
echo "--- run build.py in for v8ast"
cd ..
./build.py -d patch/v8ast

# create the patch file
cd patch
diff -uNr v8 v8ast > ast.diff

# patch the the v8patch dir
cp -r v8 v8patch
echo "--- run the patch on dir v8patch"
cd v8patch
patch -p1 < ../ast.diff

# do a diff between the built 'v8ast' dir and the patched 'v8patch' dir - should be identical
echo "do a diff between v8ast and v8patch - no difference = no output -> OK!"
cd ..
diff -r v8ast v8patch --exclude=".svn" -q

# remind to do a build and test
echo "--- DONE ---"
echo "REMINDER : to build and test the patch:"
echo "#scons mode=debug sample=shell"
echo "#chmod ug+x ast*.sh"
echo "#./shell_g example.js"
echo ""




